package com.dmall.rpc.registry;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Properties;

public class ServiceRegistry {
	/**
	 * 注册服务
	 * @param serverAddress
	 */
	public void register(String serverAddress) {
		Properties properties = new Properties();
		InputStream in = null;
		OutputStream out = null;
		try {
			URL url = this.getClass().getClassLoader().getResource("registry.properties");
			in = new FileInputStream(new File(url.getFile()));
			properties.load(in);
			properties.setProperty("server.address", serverAddress);
			out = new FileOutputStream(new File(url.getFile()));
			properties.store(out, "服务地址和端口");
		} catch (Exception e) {
		    e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}